using Log = Microsoft.Samples.ServiceHosting.HelloFabric.ApplicationEnvironment;

namespace KlearTweet.Web
{
    public static class EventLogger
    {
        private static readonly KlearStorage.FileStorage FileStorage = new KlearStorage.FileStorage("kleartweet");

        public static void Info(string action)
        {
            try
            {
                Log.LogInformation(action);
                Log.SaveLogs(FileStorage.Save); // TODO: Shouldn't flush too often! Instead, do it at the end of the request
            }
            catch (System.Exception ex)
            {
                Error("EventLogger.Info()", ex);
            }
        }

        public static string Error(string context, System.Exception ex)
        {
            string error = context + ": " + ex;
            try
            {
                Log.LogError(error);
                Log.SaveLogs(FileStorage.Save);
            }
            catch (System.Exception logEx)
            {
                error += "\n\n\n" + logEx;
            }
            return error;
        }
    }
}